/** @file post_filter.h
    @brief Postscreen filter pass */

#ifndef G3_POST_FILTER_H
#define G3_POST_FILTER_H

#include "material.h"
#include "projection.h"

#include <boost/signal.hpp>
#include <boost/signals/connection.hpp>

namespace G3 {

/** @class POSTSCREEN_PASS
    @brief One postscreen filter pass */
class POSTSCREEN_PASS {
    public:
        /**
            @brief A constructor
        */
        POSTSCREEN_PASS ();
        /**
            @brief A destructor
        */
        ~POSTSCREEN_PASS ();

        /** Pointer to the log */
        LOG *log;
        /** Filter material */
        MATERIAL material;
        /** Result texture handle */
        H_TEXTURE resultHandle;

        /** Uniform variables update event */
        typedef boost::signal3<void, POSTSCREEN_PASS *, RENDER_TO_TEXTURE *, float> SIG_UNIFORMS_EVENT;
        /** A signal connection */
        typedef boost::signals::connection SIG_CONNECTION;
        /** Uniform variables update event handler function pointer */
        typedef void (*UNIFORMS_HANDLER)(POSTSCREEN_PASS *pass, RENDER_TO_TEXTURE *r2t, float elapsedTime);
        /** Uniform variables update event signal */
        SIG_UNIFORMS_EVENT SigUniforms;
        /** All the connections to this event */
        vector<SIG_CONNECTION> ConnUniforms;
        /**
            @brief Sets the uniform variables update event handler
            @param[in] aUniformHandler Pointer to the event handler function
            @return The connection to the event signal
        */
        SIG_CONNECTION doOnSetUniforms (UNIFORMS_HANDLER aUniformHandler);

        /**
            @brief Sets the screen area to be postprocessed
            @param[in] r Reference to the area
            @return True on success, false on failure
        */
        bool Init (const RECTI &r);

        /**
            @brief Starts the postprocess pass
            @param[in] elapsedTime Elapsed time since the last call
        */
        void Begin (float elapsedTime);
        /**
            @brief Ends the postprocess pass
            @param[in] elapsedTime Elapsed time since the last call
        */
        void End (float elapsedTime);

    private:
        /** Screen area rect */
        RECTI rect;
        /** Framebuffer -> Texture renderer */
        RENDER_TO_TEXTURE renderToTex;

        /**
            @brief Renders a quad with the filter material
            @param[in] elapsedTime Elapsed time since the last call
        */
        void RenderQuad (float elapsedTime);
};

}

#endif // G3_POST_FILTER_H

